package com.wei;

/**
 * 测试为Thread定义一个处理异常的Handler
 *
 * @author :sunwei
 * @description:
 * @date create in 22:47  2021/6/17
 */
public class ThreadRuntimeExceptionHandleTest {
    private static int A = 10;
    private static int B = 0;
    
    public static void main(String[] args) {
        Thread thread = new Thread(() -> {
            try {
                System.out.println("i am working...");
                Thread.sleep(2_000);
            } catch (InterruptedException e) {
            }
            System.out.println("compute a result...");
            int result = A / B;
            System.out.println(result);
        });
        thread.setUncaughtExceptionHandler((t,e)->{
            System.out.println(t.getName()+" occur an exception : "+e);
    
            System.out.println("i am handle this exception ");
        });
        thread.start();
    }
}
